package com.zzyl.controller;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.UserDto;
import com.zzyl.service.UserService;
import com.zzyl.vo.UserVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Slf4j
@Api(tags = "用户管理")
@RequestMapping("/user")
public class UserController {
    @Autowired
    UserService userService;


    @PostMapping("/page/{pageNum}/{pageSize}")
    @ApiOperation(value = "用户管理",notes = "用户管理")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userDto",value = "用户DTO对象",required = true,dataType = "UserDto"),
            @ApiImplicitParam(paramType = "path",name = "pageNum",value = "页码",example = "1",dataType = "Integer"),
            @ApiImplicitParam(paramType = "path",name = "pageSize",value = "每页条数",example = "10",dataType = "Integer")
    })
    public ResponseResult<PageResponse<UserDto>> selectPageResponse(/*分页查询*/
            @RequestBody UserDto userDto,
            @PathVariable("pageNum") int pageNum,
            @PathVariable("pageSize") int pageSize) {
        PageResponse<UserVo> pageResponse = userService.selectPageResponse(userDto, pageNum, pageSize);
        return ResponseResult.success(pageResponse);
    }

    @PutMapping
    @ApiOperation(value = "用户添加",notes = "用户添加")
    public ResponseResult<UserVo> insertUser(@RequestBody UserDto userDto) {
        Boolean flag = userService.insertUser(userDto);
        return ResponseResult.success(flag);
    }

    @PutMapping("/is-enable/{id}/{status}")
    @ApiOperation(value = "启用和禁用",notes = "启用和禁用")
    public ResponseResult<UserVo> isEnable(@PathVariable Long id,@PathVariable String status) {
        userService.isEnable(id,status);
        return ResponseResult.success();
    }


    @DeleteMapping("/remove/{userIds}")
    @ApiOperation(value = "删除用户",notes = "删除用户")
    public ResponseResult<UserVo> deleteUser(@PathVariable List<String> userIds) {
        userService.deleteUser(userIds);
        return ResponseResult.success();
    }

    @PatchMapping
    @ApiOperation(value = "用户修改",notes = "用户修改")
    public ResponseResult<Boolean> updateUser(@RequestBody UserDto userDto) {
        return ResponseResult.success(userService.updateUser(userDto));
    }

}
